﻿using CPF;
using CPF.Animation;
using CPF.Charts;
using CPF.Controls;
using CPF.Drawing;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPFUI.IControl
{
    [CPF.Design.DesignerLoadStyle("res://CPFUI.IControl.IMControl/Stylesheet1.css")]//用于设计的时候加载样式
    public class IMListBox : Control
    {
        public StackPanel ListBox;
        //模板定义
        protected override void InitializeComponent()
        {
            ListBox = new StackPanel()
            {
                Orientation = Orientation.Vertical,
                MarginTop = 0,
                MarginLeft = 0,
                MarginRight = 0,
            };
            ScrollViewer sv = new ScrollViewer
            {
                MarginLeft = 0,
                MarginRight = 0,
                MarginTop = 0,
                MarginBottom = 0,
                Content = ListBox,
                

            };
            
            Children.Add(sv);
        }

        public void AddGroup(IMGroup group)
        {
            group.MarginLeft = 0;
            group.MarginRight = 0;
            ListBox.Children.Add(group);
        }
        public void AddItem(IMGroup group,IMListBoxItem item)
        {
            group.AddItem(item);
            item.MouseDown += Item_MouseDown;
        }
        IMListBoxItem SelectedItem;
        private void Item_MouseDown(object sender, CPF.Input.MouseButtonEventArgs e)
        {
            if(SelectedItem!=null)
            {
                SelectedItem.IsSelected = false;
                SelectedItem.Background = null;
            }
            SelectedItem = sender as IMListBoxItem; 
            SelectedItem.IsSelected = true;
            SelectedItem.Background = Color.FromArgb(100,0,153,240);
        }
    }
}
